package com.landtool.lanbase.entity;

import cn.hutool.core.date.DateUtil;
import com.landtool.lanbase.constant.CacheConsts;
import com.landtool.lanbase.elasticsearch.ElasticServer;
import com.landtool.lanbase.shipping.ShippingService;
import org.slf4j.Logger;
import org.slf4j.LoggerFactory;
import org.springframework.beans.factory.annotation.Value;
import org.springframework.context.annotation.Bean;
import org.springframework.data.annotation.Id;
import org.springframework.data.elasticsearch.annotations.Document;
import org.springframework.data.elasticsearch.annotations.Field;
import org.springframework.data.elasticsearch.annotations.FieldType;
import org.springframework.data.elasticsearch.annotations.GeoPointField;
import org.springframework.data.elasticsearch.core.geo.GeoPoint;

import java.text.ParseException;
import java.text.SimpleDateFormat;
import java.util.Date;

/**
 * 保存在数据库里面的实体类
 */
@Document(indexName="#{rollover.monthlyDateFormat}",type="_doc")
public class TgRadar {

    private static Logger log = LoggerFactory.getLogger(TgRadar.class);

    /**
     * 索引id
     */
    @Id
    private String id;

    /**
     * ais船长
     */
    @Field(type = FieldType.Double)
    private Double aislength;

    /**
     * 方向 heading  船首向
     */
    @Field(type = FieldType.Double)
    private Double direction;

    /**
     * 实时船长
     */
    @Field(type = FieldType.Double)
    private Double length;

    /**
     * 最大实时船长
     */
    @Field(type = FieldType.Double)
    private Double maxlength;

    /**
     * 最小实时船长
     */
    @Field(type = FieldType.Double)
    private Double minLength;

    /**
     * MMSI
     */
    @Field(type = FieldType.Integer)
    private Integer mmsi;

    /**
     * 数据质量
     */
    @Field(type = FieldType.Double)
    private Double quality;

    /**
     * ZMQ该目标可被扫描到的雷达ID集合
     */
    @Field(type = FieldType.Text)
    private String radarids;

    /**
     * 所属行政区
     */
    @Field(type = FieldType.Keyword)
    private String ship_belong;

    /**
     * 1:雷达模板 2:ClassA 3:ClassB 4:雷达+ClassA 5:雷达+ClassB 6:北斗融合
     */
    @Field(type = FieldType.Integer)
    private Integer ship_class;

    /**
     * 航速 节
     */
    @Field(type = FieldType.Double)
    private Double speed;

    /**
     * 雷达目标id
     */
    @Field(type = FieldType.Long)
    private Long target_id;

    /**
     * 目标名称 与船名称 一致
     */
    @Field(type = FieldType.Text)
    private String target_name;

    /**
     * 雷达发现时间  ZMQ当前时间
     */
    @Field(type = FieldType.Date)
    private Long timestamp;

    /**
     * AIS船籍 Bahamas,China,Hong Kong等
     */
    @Field(type = FieldType.Keyword)
    private String nationality;

    /**
     * AIS船类型 货船或者游船  英文名称
     */
    @Field(type = FieldType.Keyword)
    private String shiptype;

    /**
     * AIS船宽
     */
    @Field(type = FieldType.Double)
    private Double wide;

    /**
     * 接受类型 "ais"/"北斗"
     */
    @Field(type = FieldType.Keyword)
    private String aisreceiver;

    /**
     * AIS IMO
     */
    @Field(type = FieldType.Keyword)
    private String imo;

    /**
     * 船呼号
     */
    @Field(type = FieldType.Keyword)
    private String callsign;

    /**
     * 船运动方向
     */
    @Field(type = FieldType.Double)
    private Double course;

    /**
     * 目标显示ID 光电调用需要
     */
    @Field(type = FieldType.Long)
    private Integer displayid;

    /**
     * 持续时间，分钟
     */
    @Field(type = FieldType.Double)
    private Double duration;

    /**
     * 地图点坐标
     */
    @GeoPointField
    private GeoPoint geometry;


    public String getId() {
        return id;
    }

    public void setId(String id) {
        this.id = id;
    }

    public Double getAislength() {
        return aislength;
    }

    public void setAislength(Double aislength) {
        this.aislength = aislength;
    }

    public Double getDirection() {
        return direction;
    }

    public void setDirection(Double direction) {
        this.direction = direction;
    }

    public Double getLength() {
        return length;
    }

    public void setLength(Double length) {
        this.length = length;
    }

    public Double getMaxlength() {
        return maxlength;
    }

    public void setMaxlength(Double maxlength) {
        this.maxlength = maxlength;
    }

    public Integer getMmsi() {
        return mmsi;
    }

    public void setMmsi(Integer mmsi) {
        this.mmsi = mmsi;
    }

    public Double getQuality() {
        return quality;
    }

    public void setQuality(Double quality) {
        this.quality = quality;
    }

    public String getRadarids() {
        return radarids;
    }

    public void setRadarids(String radarids) {
        this.radarids = radarids;
    }

    public String getShip_belong() {
        return ship_belong;
    }

    public void setShip_belong(String ship_belong) {
        this.ship_belong = ship_belong;
    }

    public Integer getShip_class() {
        return ship_class;
    }

    public void setShip_class(Integer ship_class) {
        this.ship_class = ship_class;
    }

    public Double getSpeed() {
        return speed;
    }

    public void setSpeed(Double speed) {
        this.speed = speed;
    }

    public Long getTarget_id() {
        return target_id;
    }

    public void setTarget_id(Long target_id) {
        this.target_id = target_id;
    }

    public String getTarget_name() {
        return target_name;
    }

    public void setTarget_name(String target_name) {
        this.target_name = target_name;
    }

    public Long getTimestamp() {
        return timestamp;
    }

    public void setTimestamp(Long timestamp) {
        this.timestamp = timestamp;
    }

    public String getNationality() {
        return nationality;
    }

    public void setNationality(String nationality) {
        this.nationality = nationality;
    }

    public String getShiptype() {
        return shiptype;
    }

    public void setShiptype(String shiptype) {
        this.shiptype = shiptype;
    }

    public Double getWide() {
        return wide;
    }

    public void setWide(Double wide) {
        this.wide = wide;
    }

    public String getAisreceiver() {
        return aisreceiver;
    }

    public void setAisreceiver(String aisreceiver) {
        this.aisreceiver = aisreceiver;
    }

    public String getImo() {
        return imo;
    }

    public void setImo(String imo) {
        this.imo = imo;
    }

    public String getCallsign() {
        return callsign;
    }

    public void setCallsign(String callsign) {
        this.callsign = callsign;
    }

    public Double getCourse() {
        return course;
    }

    public void setCourse(Double course) {
        this.course = course;
    }

    public Integer getDisplayid() {
        return displayid;
    }

    public void setDisplayid(Integer displayid) {
        this.displayid = displayid;
    }

    public Double getDuration() {
        return duration;
    }

    public void setDuration(Double duration) {
        this.duration = duration;
    }

    public GeoPoint getGeometry() {
        return geometry;
    }

    public void setGeometry(GeoPoint geometry) {
        this.geometry = geometry;
    }

    public TgRadar(ShipEntity shipEntity) {
        this.aislength = shipEntity.getAislength();
        this.direction = shipEntity.getDirection();
        this.length = shipEntity.getLength();
        this.maxlength = shipEntity.getMaxlength();
        this.minLength = shipEntity.getMinlength();
        this.mmsi = shipEntity.getMmsi();
        this.quality = shipEntity.getQuality();
        this.radarids = shipEntity.getRadarids();
        this.ship_belong = shipEntity.getShip_belong();
        this.ship_class = shipEntity.getShip_class();
        this.speed = shipEntity.getSpeed();
        this.target_id = shipEntity.getTarget_id();
        this.target_name = shipEntity.getTarget_name();
        //保存在es里面的是时间戳，推送前端的是 2019-06-21 14:03:56 字符串
        SimpleDateFormat format = new SimpleDateFormat("yyyy-MM-dd HH:mm:ss");
        Date newDate = null;
        try {
            newDate = format.parse(shipEntity.getTimestamp());
        } catch (ParseException e) {
            e.printStackTrace();
            log.info("时间格式转换失败");
        }
        this.timestamp = newDate.getTime();

        this.nationality = shipEntity.getNationality();
        this.shiptype = shipEntity.getShiptype();
        this.wide = shipEntity.getWide();
        this.aisreceiver = shipEntity.getAisreceiver();
        this.imo = shipEntity.getImo();
        this.callsign = shipEntity.getCallsign();
        this.course = shipEntity.getCourse();
        this.displayid = shipEntity.getDisplayId();
        this.duration = shipEntity.getDuration();

        GeoPoint geoPoint = new GeoPoint(shipEntity.getLatitude(), shipEntity.getLongitude());
        this.geometry = geoPoint;
    }
}
